package Model;

import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

public class FaqList {

	public  ArrayList<Faq> FaqList = new ArrayList<Faq>();
	
	private DbConnection db = null;
	private Statement st = null;
	private ResultSet rs = null; 
	
	public FaqList(){
		   db = new DbConnection();	   
		   st = db.getStatement();
		   
		   try{
				this.rs = this.st.executeQuery("Select id_faq,date_pub from faq order by date_pub asc;");
				
				Faq faq = new Faq();
				
				while(this.rs.next()){
					faq.setFaq(this.rs.getInt("id_faq"));
					this.FaqList.add(faq);
				}
				
			}catch (Exception e) {
				System.out.print(e.toString());
			}   
		
	}
	
	public FaqList(int id_ad){
		   db = new DbConnection();	   
		   st = db.getStatement();
		   
		   try{
				this.rs = this.st.executeQuery("Select id_faq,date_pub from faq where id_ad="+id_ad+" order by date_pub asc;");
				
				Faq faq = new Faq();
				
				while(this.rs.next()){
					faq.setFaq(this.rs.getInt("id_faq"));
					this.FaqList.add(faq);
				}
				
				
			}catch (Exception e) {
				System.out.print(e.toString());
			}   
		
	}
	
}
